﻿using System;
using UnityEngine;

namespace AI.Graph {


    /// <summary>
    /// Add this Attribute to a node that should appear in the create node menu.
    /// </summary>
    [AttributeUsage (AttributeTargets.Class)]
    public class CreateNodeMenu : Attribute {

        public readonly string path;


        public CreateNodeMenu (string path) {
            if (string.IsNullOrEmpty (path)) {
                Debug.LogError ("The path of [CreateNodeMenu] Attribute is null or empty.");
            }

            this.path = path;
        }


        public Node CreateNew (Type type) {
            Node node = ScriptableObject.CreateInstance (type) as Node;
            string[] pathNames = path.Split ('/');
            node.name = pathNames[pathNames.Length - 1];

            return node;
        }

    }


}